// errcode.h

// Copyright (C) 2010  traxex

// Author: 	traxex <traxex@yahoo.cn>
// Created: 	30 Jul 2010
// Version: 	1.0

#pragma once

#include <cufft.h>
#define TRAXEX_CASE_STR(str)	case str: return  #str

namespace traxex{
namespace cuda{
static const char* errcode( cudaError_t err ){
    switch ( err ){
        TRAXEX_CASE_STR( cudaSuccess                           ); //  0,   ///< No errors
        TRAXEX_CASE_STR( cudaErrorMissingConfiguration         ); //  1,    Missing configuration error
        TRAXEX_CASE_STR( cudaErrorMemoryAllocation             ); //  2,    Memory allocation error
        TRAXEX_CASE_STR( cudaErrorInitializationError          ); //  3,    Initialization error
        TRAXEX_CASE_STR( cudaErrorLaunchFailure                ); //  4,    Launch failure
        TRAXEX_CASE_STR( cudaErrorPriorLaunchFailure           ); //  5,    Prior launch failure
        TRAXEX_CASE_STR( cudaErrorLaunchTimeout                ); //  6,    Launch timeout error
        TRAXEX_CASE_STR( cudaErrorLaunchOutOfResources         ); //  7,    Launch out of resources error
        TRAXEX_CASE_STR( cudaErrorInvalidDeviceFunction        ); //  8,    Invalid device function
        TRAXEX_CASE_STR( cudaErrorInvalidConfiguration         ); //  9,    Invalid configuration
        TRAXEX_CASE_STR( cudaErrorInvalidDevice                ); // 10,    Invalid device
        TRAXEX_CASE_STR( cudaErrorInvalidValue                 ); // 11,    Invalid value
        TRAXEX_CASE_STR( cudaErrorInvalidPitchValue            ); // 12,    Invalid pitch value
        TRAXEX_CASE_STR( cudaErrorInvalidSymbol                ); // 13,    Invalid symbol
        TRAXEX_CASE_STR( cudaErrorMapBufferObjectFailed        ); // 14,    Map buffer object failed
        TRAXEX_CASE_STR( cudaErrorUnmapBufferObjectFailed      ); // 15,    Unmap buffer object failed
        TRAXEX_CASE_STR( cudaErrorInvalidHostPointer           ); // 16,    Invalid host pointer
        TRAXEX_CASE_STR( cudaErrorInvalidDevicePointer         ); // 17,    Invalid device pointer
        TRAXEX_CASE_STR( cudaErrorInvalidTexture               ); // 18,    Invalid texture
        TRAXEX_CASE_STR( cudaErrorInvalidTextureBinding        ); // 19,    Invalid texture binding
        TRAXEX_CASE_STR( cudaErrorInvalidChannelDescriptor     ); // 20,    Invalid channel descriptor
        TRAXEX_CASE_STR( cudaErrorInvalidMemcpyDirection       ); // 21,    Invalid memcpy direction
        //NOTE::  deprecated
        //  This error return is deprecated as of
        //  Cuda 3.1. Variables in constant memory
        //  may now have their address taken by the
        //  runtime via ::cudaGetSymbolAddress().
        TRAXEX_CASE_STR( cudaErrorAddressOfConstant            ); // 22,    Address of constant error
        TRAXEX_CASE_STR( cudaErrorTextureFetchFailed           ); // 23,    Texture fetch failed
        TRAXEX_CASE_STR( cudaErrorTextureNotBound              ); // 24,    Texture not bound error
        TRAXEX_CASE_STR( cudaErrorSynchronizationError         ); // 25,    Synchronization error
        TRAXEX_CASE_STR( cudaErrorInvalidFilterSetting         ); // 26,    Invalid filter setting
        TRAXEX_CASE_STR( cudaErrorInvalidNormSetting           ); // 27,    Invalid norm setting
        TRAXEX_CASE_STR( cudaErrorMixedDeviceExecution         ); // 28,    Mixed device execution
        TRAXEX_CASE_STR( cudaErrorCudartUnloading              ); // 29,    CUDA runtime unloading
        TRAXEX_CASE_STR( cudaErrorUnknown                      ); // 30,    Unknown error condition
        TRAXEX_CASE_STR( cudaErrorNotYetImplemented            ); // 31,    Function not yet implemented
        TRAXEX_CASE_STR( cudaErrorMemoryValueTooLarge          ); // 32,    Memory value too large
        TRAXEX_CASE_STR( cudaErrorInvalidResourceHandle        ); // 33,    Invalid resource handle
        TRAXEX_CASE_STR( cudaErrorNotReady                     ); // 34,    Not ready error
        TRAXEX_CASE_STR( cudaErrorInsufficientDriver           ); // 35,    CUDA runtime is newer than driver
        TRAXEX_CASE_STR( cudaErrorSetOnActiveProcess           ); // 36,    Set on active process error
        TRAXEX_CASE_STR( cudaErrorInvalidSurface               ); // 37,    Invalid surface
        TRAXEX_CASE_STR( cudaErrorNoDevice                     ); // 38,    No Cuda-capable devices detected
        TRAXEX_CASE_STR( cudaErrorECCUncorrectable             ); // 39,    Uncorrectable ECC error detected
        TRAXEX_CASE_STR( cudaErrorSharedObjectSymbolNotFound   ); // 40,    Link to a shared object failed to resolve
        TRAXEX_CASE_STR( cudaErrorSharedObjectInitFailed       ); // 41,    Shared object initialization failed
        TRAXEX_CASE_STR( cudaErrorUnsupportedLimit             ); // 42,    ::cudaLimit not supported by device
        TRAXEX_CASE_STR( cudaErrorDuplicateVariableName        ); // 43,    Duplicate global variable lookup by string name
        TRAXEX_CASE_STR( cudaErrorDuplicateTextureName         ); // 44,    Duplicate texture lookup by string name
        TRAXEX_CASE_STR( cudaErrorDuplicateSurfaceName         ); // 45,    Duplicate surface lookup by string name
        TRAXEX_CASE_STR( cudaErrorDevicesUnavailable           ); // 46,    All Cuda-capable devices are busy (see ::cudaComputeMode) or unavailable
        TRAXEX_CASE_STR( cudaErrorStartupFailure               ); // 0x7f,  Startup failure
        TRAXEX_CASE_STR( cudaErrorApiFailureBase               ); // 10000  API failure base
    }
    return "UNKNOW";
}
    
static const char *errcode( cufftResult_t err){
    switch( err){
        TRAXEX_CASE_STR(	CUFFT_SUCCESS   		);
        TRAXEX_CASE_STR(	CUFFT_INVALID_PLAN   		);
        TRAXEX_CASE_STR(	CUFFT_ALLOC_FAILED   		);
        TRAXEX_CASE_STR(	CUFFT_INVALID_TYPE   		);
        TRAXEX_CASE_STR(	CUFFT_INVALID_VALUE  		);
        TRAXEX_CASE_STR(	CUFFT_INTERNAL_ERROR 		);
        TRAXEX_CASE_STR(	CUFFT_EXEC_FAILED    		);
        TRAXEX_CASE_STR(	CUFFT_SETUP_FAILED   		);
        TRAXEX_CASE_STR(	CUFFT_INVALID_SIZE   		);
    }
    return "UNKNOW";
}
}
}

#undef TRAXEX_CASE_STR
